/*
 * Copyright (c)  2017, ueboot.com
 * All rights reserved.
 * 2017-11-22 13:59:59
 */
package com.ueboot.weishop.service.activity.impl;

import com.ueboot.weishop.entity.activity.CrowResultEntity;
import com.ueboot.core.repository.BaseRepository;
import com.ueboot.weishop.repository.activity.CrowResultRepository;
import com.ueboot.core.service.impl.BaseServiceImpl;
import com.ueboot.weishop.service.activity.CrowResultService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by ziv.hung  on 2017-11-22 13:59:59.
 *
 * @author ziv.hung
 * @since 2.0 by autocode
 */
@Slf4j
@Service
public class CrowResultServiceImpl extends BaseServiceImpl<CrowResultEntity> implements CrowResultService {
    @Autowired
    private CrowResultRepository crowResultRepository;

    @Override
    protected BaseRepository getBaseRepository() {
        return crowResultRepository;
    }

    /**
     * @param activityCode
     * @param periodNum
     * @return
     */
    @Override
    public List<CrowResultEntity> findByActivityCodeAndPeriodNum(String activityCode, String periodNum) {
        return crowResultRepository.findByActivityCodeAndPeriodNum(activityCode, periodNum);
    }

    @Override
    public List<CrowResultEntity> findTop20ByLotteryOrderByOpenDateDesc(String lottery) {
        return crowResultRepository.findTop20ByLotteryOrderByOpenDateDesc(lottery);
    }

    @Override
    public List<CrowResultEntity> findByIssueDms(Integer issueDms) {
        return crowResultRepository.findByIssueDms(issueDms);
    }

    @Override
    @Transactional(rollbackFor = Exception.class, timeout = 120, propagation = Propagation.REQUIRED)
    public Integer updateIssueDmsByIssueDms(Integer issueDmsSet, Integer issueDmsWhere) {
        return crowResultRepository.updateIssueDmsByIssueDms(issueDmsSet, issueDmsWhere);
    }
}
